﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class guanliziliao : System.Web.UI.Page
{
    Datacon dataconn = new Datacon();
    Datacommand ddsj = new Datacommand();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["ID"] == null)
            {
                Response.Redirect("Default.aspx");
            }

            if (Session["diqu"] == null)
            {
                ddsj.ecDropDownList(DropDownList1, "select * from CODE_REGION where substring(CODE,3,7)='0000000' order by NAME", "NAME", "CODE");
                ddsj.ecDropDownList(DropDownList4, "select * from juming", "mingcheng", "id");
            }
            else
            {
                ddsj.ecDropDownList(DropDownList1, "select * from CODE_REGION where substring(CODE,3,7)='0000000' order by NAME", "NAME", "CODE");
                DropDownList1.SelectedValue = Session["diqu"].ToString().Substring(0, 2) + "0000000";
                ddsj.ecDropDownList(DropDownList2, "select * from CODE_REGION where substring(CODE,3,7)<>'0000000' and substring(CODE,5,5)='00000' and substring(CODE,1,2)='" + DropDownList1.SelectedValue.Substring(0, 2) + "' order by NAME", "NAME", "CODE");
                DropDownList2.SelectedValue = Session["diqu"].ToString().Substring(0, 4) + "00000";
                ddsj.ecDropDownList(DropDownList3, "select * from CODE_REGION where substring(CODE,3,7)<>'0000000' and substring(CODE,5,5)<>'00000' and substring(CODE,7,3)='000' and substring(CODE,1,4)='" + DropDownList2.SelectedValue.Substring(0, 4) + "' order by NAME", "NAME", "CODE");
                DropDownList3.SelectedValue = Session["diqu"].ToString().Substring(0, 6) + "000";
                ddsj.ecDropDownList(DropDownList4, "select * from juming", "mingcheng", "id");

                ddsj.bindinfostring(GridView1, "SELECT a.id as id,a.riqi as riqi,a.lxr as lxr,a.nr +'  经办人：'+a.jbr+' '+b.qingkuang as nr,a.dh as dh  FROM lianxijilu a,qingkuangjilu b where a.dqqk=b.id and a.danweiid in (select id from danwei where diquhao='" + DropDownList3.SelectedValue + "' and juhao=" + DropDownList4.SelectedValue + ") order by id desc", "ID");

                Session["diqu"] = "";
                Session["juhao"] = "";
            }


        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddsj.ecDropDownList(DropDownList2, "select * from CODE_REGION where substring(CODE,3,7)<>'0000000' and substring(CODE,5,5)='00000' and substring(CODE,1,2)='" + DropDownList1.SelectedValue.Substring(0, 2) + "' order by NAME", "NAME", "CODE");
    }
    protected void DropDownList1_TextChanged(object sender, EventArgs e)
    {
        //ddsj.ecDropDownList(DropDownList2, "select * from CODE_REGION where substring(CODE,3,7)<>'0000000' and substring(CODE,5,5)='00000' and substring(CODE,1,2)='" + DropDownList1.SelectedValue.Substring(1, 2) + "' order by CODE", "NAME", "CODE");

    }
    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {
        ddsj.ecDropDownList(DropDownList3, "select * from CODE_REGION where substring(CODE,3,7)<>'0000000' and substring(CODE,5,5)<>'00000' and substring(CODE,7,3)='000' and substring(CODE,1,4)='" + DropDownList2.SelectedValue.Substring(0, 4) + "' order by NAME", "NAME", "CODE");

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Session["diqu"] = DropDownList3.SelectedValue;
        Session["juhao"] = DropDownList4.SelectedValue;
        ddsj.bindinfostring(GridView1, "SELECT a.id as id,a.riqi as riqi,a.lxr as lxr,a.nr +'  经办人：'+a.jbr+' '+b.qingkuang as nr,a.dh as dh FROM lianxijilu a,qingkuangjilu b where a.dqqk=b.id and a.danweiid in (select id from danwei where diquhao='" + DropDownList3.SelectedValue + "' and juhao=" + DropDownList4.SelectedValue + ") order by id desc", "ID");

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        
        if (Session["diqu"] != null)
        {
            Response.Redirect("addjilu.aspx");
        }
        else
        {
            Response.Write("<script language=javascript>alert('请先查询该单位情况 ！')</script>");
        }

    }
    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["diqu"] = DropDownList3.SelectedValue;
        Session["juhao"] = DropDownList4.SelectedValue;
    }
    protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["diqu"] = DropDownList3.SelectedValue;
        Session["juhao"] = DropDownList4.SelectedValue;
    }
    protected void DropDownList3_Disposed(object sender, EventArgs e)
    {
        Session["diqu"] = DropDownList3.SelectedValue;
        Session["juhao"] = DropDownList4.SelectedValue;
    }
    protected void DropDownList4_Disposed(object sender, EventArgs e)
    {
        Session["diqu"] = DropDownList3.SelectedValue;
        Session["juhao"] = DropDownList4.SelectedValue;
    }
}